package com.ccjq.jq173.shosestore.core.util;

public class PageBean
{
	private int totalRows;  //总行数
	private int pageSize;	//每页显示几行
	private int totalPages;	//总页数
	private int currentPage;//当前页数
	private int startRow;	//当前页起始行

	public PageBean(int _totalRows)
	{
		this.totalRows=_totalRows;
		this.pageSize=4;
		this.currentPage=1;	//当前行数为1
		this.startRow=1;	//其实行数为1
		this.totalPages=(totalRows%pageSize==0)?(totalRows/pageSize):(totalRows/pageSize+1);
	}
	public PageBean(int _totalRows,int pageSize)
	{
		this.totalRows=_totalRows;
		this.pageSize=pageSize;
		this.currentPage=1;	//当前行数为1
		this.startRow=1;	//其实行数为1
		this.totalPages=(totalRows%pageSize==0)?(totalRows/pageSize):(totalRows/pageSize+1);
	}
	//首页
	public void first()
	{
		currentPage=1;
		startRow=1;
	}

	//上一页
	public void previous()
	{
		if(currentPage==1)  //当前页位第一页时不调用
			return;
		startRow=(--currentPage-1)*pageSize+1;
	}

	//下一页
	public void next()
	{
		if(currentPage<totalPages)
		{
			currentPage++;
		}
		startRow=(currentPage-1)*pageSize+1;
	}
	//尾页
	public void last()
	{
		currentPage=totalPages;
		startRow=(currentPage-1)*pageSize+1;
	}

	//跳转
	public void refresh(int _currentPage)
	{
		currentPage=_currentPage;
		if(currentPage>totalPages)
		{
			this.last();
		}
		else if(currentPage<1)
		{
			this.first();
		}
		startRow=(currentPage-1)*pageSize+1;
	}

	public int getTotalRows() {
		return totalRows;
	}
	public void setTotalRows(int totalRows) {
		this.totalRows = totalRows;
	}
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public int getTotalPages() {
		return totalPages;
	}
	public void setTotalPages(int totalPages) {
		this.totalPages = totalPages;
	}
	public int getCurrentPage() {
		return currentPage;
	}
	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}
	public int getStartRow() {
		return startRow;
	}
	public void setStartRow(int startRow) {
		this.startRow = startRow;
	}
	
}
